package com.wlstock.funi.ui;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.em.baselistener.OnMoreListener;
import com.em.widget.view.SelectPopUpWindow.onPopViewListener;
import com.wlstock.funi.R;
import com.wlstock.funi.dao.PositionDao;
import com.wlstock.funi.model.PositionModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LocalDataActivity extends FundBaseActivity implements OnMoreListener, onPopViewListener {
	
	private ListView lv_base;
	private ArrayList<String> datas;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_base_lv);
		showMoreBtn(this);
		lv_base = (ListView) findViewById(R.id.lv_base);
	}

	@Override
	public void onMoreClick(View v) {
		showPopUpView(getMenuList(), this);
		
	}

	private List<Map<String, Object>> getMenuList() {
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", getResources().getString(R.string.pop_title_dao_position));
		list.add(map);
		
		return list;
	}

	private void setList(List<? extends Object> datas) {
		if (datas == null || datas.size() == 0) {
			return;
		}
		ArrayList<Map<String, Object>> adapterList = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < datas.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("value", datas.get(i).toString());
			adapterList.add(map);
		}	
		SimpleAdapter sAdapter = new SimpleAdapter(this, adapterList, R.layout.list_item_simple_tv , new String[]{"value"}, new int[]{R.id.tv_simple_info});
		lv_base.setAdapter(sAdapter);
	}

	@Override
	public void onViewSelectListener(String str) {
		if (getResources().getString(R.string.pop_title_dao_position).equals(str)) {
			List<PositionModel> positions = PositionDao.getInstance(this).queryAll();
			setList(positions);
		} else if (getResources().getString(R.string.pop_title_dao_wanglong_trade).equals(str)) {
			
		} else if (getResources().getString(R.string.pop_title_dao_selffund).equals(str)) {
			
		} else if (getResources().getString(R.string.pop_title_valiable).equals(str)) {
			
		}
	}
	
}
